package com.example.qxfw.dataBaseManager.nyzjk.controller;

import com.example.qxfw.common.SysResult;
import com.example.qxfw.common.entity.ny.BadCondition;
import com.example.qxfw.common.entity.ny.Goodcondition;
import com.example.qxfw.common.entity.ny.StationInfo;
import com.example.qxfw.dataBaseManager.nyzjk.service.TjszService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import springfox.documentation.annotations.ApiIgnore;

import java.util.List;

/************************************
 *
 * @author : HuangDeYin Jolly
 * @since : JDK 11
 * @Date : 2023/7/6  星期四   10:44
 * @description : 此类用来 条件设置
 ***************************************/

@ApiIgnore
@Slf4j
@Api(tags = "数据库管理-农业专家库-条件设置")
@RestController
@CrossOrigin
@RequestMapping("/TjszController")
public class TjszController {

    @Autowired
    private TjszService tjszService;

    @ApiOperation("根据之编号查询不利条件")
    @GetMapping("selectByIndexId")
    public SysResult selectByIndexId(Long indexId) {
        List<BadCondition> badConditionList = this.tjszService.selectByIndexId(indexId);
        return SysResult.success(badConditionList);
    }


    @ApiOperation("添加")
    @PostMapping("saveBadCondition")
    public SysResult saveBadCondition(@RequestBody BadCondition badCondition) {
        List<BadCondition> badConditions = this.tjszService.selectByIndexId(badCondition.getIndexid());
        if (badConditions.size() > 0) {
            return SysResult.fail("已存在");
        } else {
            Integer integer = this.tjszService.insertBadCondition(badCondition);
            if (integer > 0) {
                return SysResult.success();
            } else {
                return SysResult.fail();
            }
        }
    }

    @ApiOperation("修改")
    @PostMapping("updateBadCondition")
    public SysResult updateBadCondition(@RequestBody BadCondition badCondition) {
        Integer integer = this.tjszService.updateBadCondition(badCondition);
        if (integer > 0) {
            return SysResult.success();
        } else {
            return SysResult.fail();
        }
    }

    @ApiOperation("删除")
    @PostMapping("deleteBadCondition")
    public SysResult deleteBadCondition(@RequestBody BadCondition badCondition) {
        Integer integer = this.tjszService.deleteBadCondition(badCondition);
        if (integer > 0) {
            return SysResult.success();
        } else {
            return SysResult.fail();
        }
    }

    @ApiOperation("查询所有stationInfo站点信息表")
    @GetMapping("selectStationInfo")
    public SysResult selectStationInfo(){
        List<StationInfo> stationInfoList = this.tjszService.selectStationInfo();
        return SysResult.success(stationInfoList);
    }

    @ApiOperation("查询所有的有利条件")
    @GetMapping("selectGoodCondition")
    public SysResult selectGoodCondition(Long indexId){
        List<Goodcondition> goodconditions = this.tjszService.selectGoodCondition(indexId);
        return SysResult.success(goodconditions);
    }

    @ApiOperation("添加有利条件")
    @PostMapping("saveGoodCondition")
    public SysResult saveGoodCondition(@RequestBody Goodcondition goodcondition){
        Integer integer = this.tjszService.saveGoodCondition(goodcondition);
        if (integer > 0) {
            return SysResult.success();
        } else {
            return SysResult.fail();
        }
    }

    @ApiOperation("修改有利条件")
    @PostMapping("updateGoodCondition")
    public SysResult updateGoodCondition(@RequestBody Goodcondition goodcondition){
        Integer integer = this.tjszService.updateGoodCondition(goodcondition);
        if (integer > 0) {
            return SysResult.success();
        } else {
            return SysResult.fail();
        }
    }

    @ApiOperation("删除有利条件")
    @PostMapping("deleteGoodCondition")
    public SysResult deleteGoodCondition(@RequestBody Goodcondition goodcondition){
        Integer integer = this.tjszService.deleteGoodCondition(goodcondition);
        if (integer > 0) {
            return SysResult.success();
        } else {
            return SysResult.fail();
        }
    }




}
